package com.jp.knowledge.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.KnolagePackage;
import com.jp.knowledge.util.ImageLoadUtil;
import com.jp.knowledge.util.TimeUtil;

import java.util.List;
import java.util.Map;

/**
 * Created by jiayen on 17/6/5.
 */

public class KnowlageDetailAdapter extends  JpBaseRecyViewAdapter {
    public KnowlageDetailAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    public int getLayoutId() {
        return R.layout.konwlage_detail_item;
    }

    @Override
    public void bindViewHold(JPRecycleViewHolder holder, int position) {
        KnolagePackage pg= (KnolagePackage) getItem(position);

        LinearLayout      fileLayout = holder.getView(R.id.file_layout);
        RelativeLayout  detailLayout = holder.getView(R.id.detail_layout);
        if(pg.getType()==1){//详情内容
            fileLayout.setVisibility(View.GONE);
            detailLayout.setVisibility(View.VISIBLE);
            TextView   time = holder.getView(R.id.time);
            TextView   content = holder.getView(R.id.content);
            ImageView   img_icon = holder.getView(R.id.img_icon);

            time.setText(TimeUtil.friendly_time(pg.getCreatetime()));
            content.setText(pg.getTitle());
            String icon = "";
            try {
                 icon = pg.getImglist().get(0).getSrc();

            }catch (Exception e){

            }

            if(TextUtils.isEmpty(icon)){
                img_icon.setVisibility(View.GONE);
            }else {
                ImageLoadUtil.load(mContext,icon,img_icon,100,100);
                img_icon.setVisibility(View.VISIBLE);
            }

        }else {//目录内容
            fileLayout.setVisibility(View.VISIBLE);
            detailLayout.setVisibility(View.GONE);

            TextView name = holder.getView(R.id.name);
            ImageView icon = holder.getView(R.id.icon);
            name.setText(pg.getTitle());
        }

    }
}
